package com.yootk.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 自定义的消息监听方法
 * JSR-250注解管理生命周期
 */
@Component
public class MessageListener3 {
    private static final Logger LOGGER = LoggerFactory.getLogger(MessageListener3.class);

    // 消息的接收处理
    public void onReciever(String msg) {
        LOGGER.info("【接收到新消息】{}", msg);
    }

    @PostConstruct  // 初始化方法
    public void openChannel() throws Exception {
        LOGGER.info("【通道连接】服务器消息通道建立成功。");
    }

    @PreDestroy     // 销毁方法
    public void closeChannel() throws Exception {
        LOGGER.info("【通道关闭】断开服务器连接，关闭消息监听服务。");
    }
}
